<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>jQuery基础教程之遍历-遍历实例</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>each</h1>
<hr>

<div id="box">
    <ul>
        <li class="fruit">苹果</li>
        <li class="vg">西红柿</li>
        <li class="vg">黄瓜</li>
        <li class="fruit">草莓</li>
        <li class="vg">土豆</li>
        <li class="fruit">葡萄</li>
        <li class="vg">南瓜</li>
        <li class="vg">香菇</li>
    </ul>
    <ul>
        <li>牛奶</li>
        <li>面包</li>
        <li>香肠</li>
        <li>鸡蛋</li>
    </ul>
</div>

<script>

    $(function(){
        $("li").each(function(i,e){
            console.log("第"+i+"个元素是"+$(e).text());
        })
    })
</script>
</body>
</html>


